import tweepy
import time
import os
consumer_key="GahOOLF67J09yD6pe99YlUIQE"
consumer_secret="bw5Ks3i4Fbx2WWhhdmXR7lumJkvUubjbKNL8MrgxYihutKDgJ0"
access_token="821980639461195776-j4HXtSffLMlXmznaNWGm73r8DtZaYiJ"
access_token_secret="eQ3Qa5SQJilTJTeD5pdAgJxJXzTmHBYvWo5nLnVxAueVx"

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

# t = api.get_status('672070053509079040')
# print t

import glob

files = glob.glob('Subtask_A/*')

for file in files:


    with open(file) as f:
        count = 0
        file_save = str(file).replace("Subtask_A", "twitter")
        if (os.path.isfile(file_save)):
            init_ids = [x.split()[0] for x in open(file_save).readlines()]
        for line in f:
            count += 1
            content = line
            sid = line.split()[0]
            if (sid in init_ids):
                continue
            try:
                time.sleep(2)
                status = api.get_status(sid)
                text = status.text
                text = text.replace('\n'," ")
            except tweepy.error.TweepError, e:
                text = e
            finally:
                print count, sid, text

                with open(file_save, "a+") as fs:
                    fs.write(sid+'\t'+str(text)+"\n")
